<?php
include_once('_path.php');

include_once(_CONST_LOCAL_INCLUDE_PATH."database.class.php");
$database = new Database($db_vars);

include_once(_CONST_LOCAL_INCLUDE_PATH."common.php");

#用户信息
include_once(_CONST_LOCAL_INCLUDE_PATH."session.include.php");

$vote_id = intval($_GET["vote_id"]);
$page = intval($_GET['page']);
$pagesize =5;

#所有条目
$sql = "SELECT count(*) as total FROM vote_comment WHERE vote_id = " .$vote_id;
$rs = $database->queryFirst($sql);
$total_r = $rs["total"];

$total_pages = ceil($total_r / $pagesize);
if($page>$total_pages)
$page = 1;
?>
<!--上面是没有回复的样式，下面是有回复的样式-->
<?php 
	$rc = $database->queryArray("SELECT vc.*, ui.avatar FROM vote_comment vc LEFT JOIN user_info ui ON ui.id = vc.user_id  WHERE vc.vote_id = " .$vote_id . " ORDER BY vc.id DESC LIMIT ".(($page - 1) * $pagesize) . ", $pagesize");
	foreach($rc as $c) {
?>
		<div class="comment-list clearfix">
			<a href="<?php echo _CONST_WEB_URL . 'homepage?id='.$c['user_id'];?>"><img class="comment-user-image" src="<?php echo iif(!empty($c['avatar']), _CONST_PIC_URL . 'avatar/' . $c['user_id'] . '/2_' . $c['avatar'], _CONST_IMG_URL . 'avatar/2.jpg')?>" alt="<?php echo $c['postname'] ?>" /></a>
			<div class="comment-user-name"><a href="<?php echo _CONST_WEB_URL . 'homepage?id='.$c['user_id'];?>"><?php echo $c['postname'] ?></a><span class="comment-time"><?php echo date('Y-m-d H:i:s', $c['posttime']);?></span></div>
			<div class="reply-to-comment"><?php echo htmlspecialchars($c['postcontent'])?></div>	
			<?php
			if($_SESSION['buserid']>0 || $_SESSION['userid'] == $c['user_id']){
			?>
			<div class="comment-del"><a href="javascript:;" onclick="deletes(this,<?php echo $c['id'];?>);">删除</a></div>
		   <?php
			}		   
		   ?>
		</div>
<?php
	}
?>	
<?php pagination_comment_ajax($page,$pagesize,$total_r,"%s%.htm") ?>